#@laybase() 
#define main()
	
	<style>
		#filter{
			width:8rem;
			margin-bottom:-4rem;
		}
	
	
		#userManager{
			text-align:center;
			vertical-align:middle;
		}
		#userDetail td{
			text-valign:center;
			vertical-align:middle;
		}
		#userManager td:last-child>a:nth-child(2){
			margin:0 5px;
		}
		
		
		
		#userIdCardPhoto{
			display:flex;
			width:100%;
			
		}
		#userIdCardPhoto li{
			margin:0 1rem;
		}
		#userIdCardPhoto div{
			width:10rem;
			height:11rem;
			text-align:center;
		}
		#userIdCardPhoto div>img{
			width:100%;
			height:10rem;
		}
	</style>
	
	<form>
		<select  id='filter' class='form-control'>
			<option value=''>-请选择-</option>
			<option value='4'>已通过</option>
			<option value='2'>待审核</option>
			<option value='3'>反馈中</option>
			<option value='1'>已拒绝</option>
		</select>
	</form>
	
	<div class='table-responsive' id='userManager'>
		<table class='table table-bordered'>
			
		</table>
	</div>
		
	<!-- Modal -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">查看照片</h4>
	      </div>
	      <div class="modal-body">
			<ul id='userIdCardPhoto'>
			</ul>
	      </div>
	    </div>
	  </div>
	</div>
	
	<div class="modal fade"  id='userIdCardPhotoModal' tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">照片预览</h4>
	      </div>
	      <div class="modal-body" id='userIdCardPhotoModalPreview'>
	      </div>
	    </div>
	  </div>
	</div>
	
	<div class="modal fade"  id='descMsgModal' tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">反馈内容</h4>
	      </div>
	      <div class="modal-body" id='descMsg'>
	      	<textarea class="form-control" rows="3"></textarea>
	      </div>
	      <div class="modal-footer">
	      	<button class='btn btn-info' id='descBtn' data-dismiss="modal" data-id='' data-progress=''>提交反馈</button>
	      </div>
	    </div>
	  </div>
	</div>
	
	<script>
	
	$(function(){
		
		$.ajax({
			type:'get',
			url:'/admin/reviewUserQuery',
			success:function(data){
				console.log(data);
				$('#userManager table').bootstrapTable({
				    columns: [{
				        field: 'userName',
				        title: '用户名'
				    }, {
				        field: 'userPhone',
				        title: '手机号码'
				    }, {
				        field: 'idNo',
				        title: '身份证号码'
				    }, {
				        field: 'refereeName',
				        title: '邀请人姓名'
				    },{
				        field: 'regTime',
				        title: '注册时间'
				    },{
				        field: 'idCardPhoto',
				        title: '身份证照片'
				    },{
				        field: 'progresstxt',
				        title: '审核状态'
				    },{
				        field: 'isPass',
				        title: '是否通过审核'
				    }],
				    data: getData(data),
				    search: true,
					pagination: true, 
		            pageSize: 10
				});
			}
		})
		
		$('#userManager table').on('click','a[data-id]',function(){
			var userID = $(this).attr('data-id');
			
			//请求图片
			$.ajax({
				type:'get',
				url:'/admin/reviewUserQuery',
				data:{
					userID:userID
				},
				success:function(data){
					var userIdCardPhotoHtml = '';
					var idCardPhotoArr = data.idCardPhoto.split(',');
					
					for(var r=0;r<idCardPhotoArr.length;r++){

						var idCardPhotoNameStart= idCardPhotoArr[r].lastIndexOf('/');
						var idCardPhotoNameEnd= idCardPhotoArr[r].indexOf('.');
						
						var idCardPhotoName = idCardPhotoArr[r].substring(idCardPhotoNameStart+1,idCardPhotoNameEnd);

						userIdCardPhotoHtml += '<li><div><img src="'+idCardPhotoArr[r]+'" alt="照片读取失败，稍后重试" data-toggle="modal" data-target="#userIdCardPhotoModal" /><span>'+idCardPhotoName+'</span></div></li>'
					}
					$('#userIdCardPhoto').html(userIdCardPhotoHtml);
					
				}
			}) 
			
		})

		//图片预览	
		$('#userIdCardPhoto').on('click','img',function(){
			var src = $(this).attr('src');
			var width = $(this)
			var lgImg=$("<div></div>")
			
			lgImg.css({
				width:'500px',
				height:'500px',
				position: "relative"
				
			})
			lgImg.iviewer({
                src: src
           	});
			
			$('#userIdCardPhotoModalPreview').html(lgImg);
			
		})
		
		
		
		//筛选
		$('#filter').change(function(){

			var val = $(this).val();

			$.ajax({
				type:'get',
				url:'/admin/getUserByProgress',
				data:{
					progress:val
				},
				success:function(data){
					$('#userManager table').bootstrapTable('load', getData(data));
					
				}
			})
		})
		
		//反馈
		$('#userManager table').on('click','a[data-progress]',function(){
			var progress = $(this).data('progress');
			var userID = $(this).parent().siblings().children('a[data-id]').data('id');
			var msg = '';
			
			$('#descBtn').data('progress',progress);
			$('#descBtn').data('id',userID);
			
			console.log(progress,userID );
			if( $(this).hasClass('nodesc') ){
				$.ajax({
					type:'get',
					url:'/admin/reviewUser',
					data:{
						userID:userID,
						progress:progress
					},
					success:function(data){
						if(data.code == 1){
							msg = data.msg
							_x.show_alert_sh(msg,true)
						}else{
							msg = data.msg
							_x.show_alert_sh(msg,false)
						}
					}
				})
			}
		})

		$('#descBtn').click(function(){
			var descMsg = $('#descMsg textarea').val();
			var progress = $(this).data('progress');
			var userID = $(this).data('id');
			
			if(_x.isEmpty(descMsg)){
				_x.show_alert_sh('请输入反馈内容',false)
				return;
			}
			
				$.ajax({
					type:'get',
					url:'/admin/reviewUser',
					data:{
						userID:userID,
						progress:progress,
						descMsg:descMsg
					},
					success:function(data){
						if(data.code == 1){
							msg = data.msg
							_x.show_alert_sh(msg,true)
						}else{
							msg = data.msg
							_x.show_alert_sh(msg,false)
						}
					}
				})
		})
		
		
		
		
		//for封装
		function getData(data){
			for(var i=0;i<data.length;i++){
				data[i].idCardPhoto = '<a class="btn btn-primary" data-toggle="modal" data-target="#myModal" data-id="'+data[i].id+'">查看照片</a>'
				data[i].isPass = '<a class="btn btn-success nodesc" data-progress="4" data-nodesc>通过</a>'+
								'<a class="btn btn-warning" data-progress="3" data-toggle="modal" data-target="#descMsgModal" >反馈信息</a>'
				var progresstxt = ""
				var idCardPhotoArr = data[i].idCardPhoto.split(',');
				var progress = data[i].progress;
				var progressInfo = '';
				if(progress===1){
					progresstxt = '已拒绝' 
				}else if(progress===2){
					progresstxt = '待审核' 
				}else if(progress===3){
					progresstxt = '有反馈' 
				}else{
					progresstxt = '已通过' 
				}
				
				data[i].progresstxt = progresstxt
			}
			
			return data;
		}
		
	})
		
		
	</script>
#end